package io.renren.common.utils;

import java.lang.reflect.Field;
import java.util.Map;
import java.util.Set;

/**
 * @author LuoShun
 * @emall Lori6166@163.com
 * @date 2022/1/8 20:31
 */
public class MyUtils {
    // copy Map中的属性 到 实体类中
    public static void copyMapToObject(Map<Object, Object> map, Object o) {
        Set<Object> set = map.keySet();
        Class c = o.getClass();
        Field[] fields = c.getDeclaredFields();
        for (Field f : fields) {
            f.setAccessible(true);
            if (set.contains(f.getName())){
                try {
                    f.set(o, map.get(f.getName()));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
